package com.example.juc.add;

import java.util.concurrent.CountDownLatch;
// 计数器
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(6);

        for (int i =1 ;i<=6;i++){
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+" go out");
                latch.countDown();
            },String.valueOf(i)).start();
        }
        latch.await(); // 等待计数归0执行
        System.out.println("关门");
    }
}
